package cn.exrick.xboot.modules.transport.controller;

import cn.exrick.xboot.common.utils.ResultUtil;
import cn.exrick.xboot.common.vo.Result;
import cn.exrick.xboot.modules.transport.baoxian.dto.*;
import cn.exrick.xboot.modules.transport.baoxian.service.InsuranceService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.xml.bind.JAXBException;
import java.math.BigDecimal;

/**
 * @author gj
 */
@Slf4j
@RestController
@Api(tags = "第三方保险对接表，记录与第三方保险的对接信息管理接口")
@RequestMapping("/xboot/thirdPartyInsurance")
@Transactional
public class ThirdPartyInsuranceController {

    @Autowired
    private InsuranceService insuranceService;


    @RequestMapping(value = "/getInsuranceRate", method = RequestMethod.GET)
    @ApiOperation(value = "根据目的地获取费率测试")
    public Result<String> getInsuranceRate(
            @ApiParam(value = "目的地编码", required = true) String toLoc) throws JAXBException {
        RateQueryRequest request = new RateQueryRequest();
        request.getPolicy().setToLoc(toLoc);
        RateQueryResponse rateQueryResponse = insuranceService.queryRate(request);
        return new ResultUtil<String>().setData(rateQueryResponse.getPolicy().getRatio());
    }

    @RequestMapping(value = "/getInsuranceTest", method = RequestMethod.GET)
    @ApiOperation(value = "下单测试")
    public Result<String> getInsuranceTest() throws JAXBException {
        InsuranceApplicationRequest insuranceApplicationRequest = new InsuranceApplicationRequest();
        insuranceApplicationRequest.getPolicy().setTransport("11223344");
        insuranceApplicationRequest.getPolicy().setPrimaryNo("55667788");
        insuranceApplicationRequest.getPolicy().setFromLoc("110108");
        insuranceApplicationRequest.getPolicy().setToLoc("441322");
        insuranceApplicationRequest.getPolicy().setDepartureDate("2025-04-03:09");
        insuranceApplicationRequest.getPolicy().setEffDate("2025-04-03:08");
        insuranceApplicationRequest.getPolicy().setInsuredAmount(new BigDecimal("10000.00"));
        InsuranceApplyResponse insuranceApplyResponse = insuranceService.submitApplication(insuranceApplicationRequest);
        return new ResultUtil<String>().setData("");
    }

    @RequestMapping(value = "/getInsuranceDetail", method = RequestMethod.GET)
    @ApiOperation(value = "获取保险单测试")
    public Result<String> getInsuranceDetail(@ApiParam(value = "目的地编码", required = true) String policyNo) throws JAXBException {
        PolicyQueryResponse policyQueryResponse = insuranceService.queryPolicy(policyNo);
        return new ResultUtil<String>().setData("");
    }

}
